package com.example.design.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

     @Bean
     public DirectExchange noramlExchange() {
         return new DirectExchange("normalExchange",true,false);
     }

     @Bean
     public Queue noramlQueue() {
         return QueueBuilder.durable("normalQueue")
                 .withArgument("x-dead-letter-exchange", "deadExchange")
                 .withArgument("x-dead-letter-routing-key", "deadKey").build();
     }

     @Bean
     public Binding binding() {
         return new Binding("normalQueue", Binding.DestinationType.QUEUE, "normalExchange", "normalKey", null);
     }

     //声明死信队列
     @Bean
     public Queue deadQueue() {
         return new Queue("deadQueue",true);
     }

     //声明死信交换机
     @Bean
     public DirectExchange deadExchange() {
         return new DirectExchange("deadExchange",true,false);
     }
     ////绑定死信队列
     @Bean
     public Binding deadBinding() {
         return new Binding("deadQueue", Binding.DestinationType.QUEUE, "deadExchange", "deadKey", null);
     }

}
